<?php $header=$this->action('ZfcAdmin\Controller\AdminController', 'headerAction');
	  $baseUrl = $header->headerarray['baseUrl'];
?>
<html>
	<body>
		<center>
		<h1>SubCategories</h1>
			<form id="sub_cat_form" name="sub_cat_form" method="post" action="">
					<div>
						Category Name:<input type="text" readonly id="category_name" name="category_name" value="<?php echo $this->CategoryList->category_name?>">
						<input type="hidden" id="category" name="category" value="<?php echo $this->CategoryList->category_id?>">
					</div><br/>
					Sub category:<br/>
					<div id="subdiv">
					<? if($this->count_sub_categories>0){?>
					<? $sub_num=0;foreach($this->subcategoriesList as $sub_category){?>
						<div id ="txtdiv<? echo $sub_num;?>">
							<input type="text" id="name<? echo $sub_num;?>" name="name[]" value="<? echo $sub_category->sub_category_name;?>">
							&nbsp;&nbsp;							
							<input type="button" <? if($sub_num<=(count($this->subcategoriesList)-2)){?> style="display:none;"<?}?>  onclick="addTextBox()" id="add<? echo $sub_num;?>" value="+">
							<input type="button" <? if($sub_num==(count($this->subcategoriesList)-1)){?> style="display:none;"<?}?>  onclick="removeTextBox()" id="remove<? echo $sub_num;?>" value="-"><br/>
						</div>	
					<?$sub_num++;}?>					
					<?}else{?>
						<div id ="txtdiv0">
							<input type="text" id="name0" name="name[]">&nbsp;&nbsp;
							<input type="button" onclick="addTextBox()" id="add0" value="+">
							<input type="button" onclick="removeTextBox()" id="remove0" style="display:none;" value="-"><br/>
						</div>	
					<?}?>
					</div>	<br/>				
					<a href="<? echo $baseUrl.'admin/category'?>">Back</a>&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" id="btn_sub_cat" name="btn_sub_cat" value="Save" onclick="return add_sub_categories()">
					<input type="hidden" id="hid_count" name="hid_count" value="<?php if(isset($this->count_sub_categories) && $this->count_sub_categories!=""){echo $this->count_sub_categories;}else{echo '0';}?>">					
			</form>
		</center>
	</body>
</html>
<script>
var i=0;
if(parseInt($('#hid_count').val())>0){
	i= $('#hid_count').val()-1;
}
function addTextBox(){
	i++;
	$('#subdiv').append('<div id = "txtdiv'+i+'"><input type="text" id="name'+i+'"  name="name[]">&nbsp;&nbsp;<input type="button" onclick="addTextBox()" id="add'+i+'" value="+"><input type="button" onclick="removeTextBox()" id="remove'+i+'" value="-"></div>');
	var j = i - 1;
	$('#remove'+j).show();
	$('#remove'+i).hide();
	$('#add'+j).hide();
	
}
function removeTextBox(){
	$('#txtdiv'+i).remove();
	i--;
	$('#remove'+i).hide();
	$('#add'+i).show();
}
</script>